﻿using UnityEngine;

namespace winS.Unity.Geometry
{
    /// <summary>
    /// 圆形
    /// </summary>
    public readonly struct Circle
    {
        /// <summary>
        /// 半径
        /// </summary>
        public readonly float radius { get; }
        /// <summary>
        /// 圆心点
        /// </summary>
        public readonly Vector2 center { get; }

        public Circle(Vector2 center, float radius)
        {
            this.center = center;
            this.radius = radius;
        }

        /// <summary>
        /// 是否包含点 <paramref name="point"/>
        /// </summary>
        public bool Contains(Vector2 point)
        {
            return Vector3.Distance(center, point) < radius;
        }

        /// <summary>
        /// 是否与矩形 <paramref name="rect"/> 重叠
        /// </summary>
        public bool Overlap(Rect rect)
        {
            return rect.Overlap(this);
        }
        /// <summary>
        /// 是否与圆形 <paramref name="circle"/> 重叠
        /// </summary>
        public bool Overlap(Circle circle)
        {
            return Vector2.Distance(center, circle.center) < radius + circle.radius;
        }
    }

}
